﻿using HML.Design;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace HML
{
    /// <summary>
    /// SingleAccordion标签节点样式(通用)
    /// </summary>
    [TypeConverter(typeof(PropertyOrderConverter))]
    public class SingleAccordionLabelNodeStyle
    {
        #region 属性

        private bool mouseAnimationEnabled = false;
        /// <summary>
        /// 是否启用节点鼠标动画
        /// </summary>
        [Description("是否启用节点鼠标动画")]
        [Category("杂项")]
        [PropertyOrder(-196)]
        [DefaultValue(false)]
        public bool MouseAnimationEnabled
        {
            get { return this.mouseAnimationEnabled; }
            set
            {
                if (this.mouseAnimationEnabled == value)
                    return;

                this.mouseAnimationEnabled = value;
                if (!value && this.owner != null)
                {
                    this.owner.RemoveNodeMouseAnimation();
                }
            }
        }

        private int mouseAnimationAllTimer = 150;
        /// <summary>
        /// 鼠标动画总时间(毫秒)
        /// </summary>
        [Description("鼠标动画总时间(毫秒)")]
        [Category("杂项")]
        [PropertyOrder(-190)]
        [DefaultValue(150)]
        public int MouseAnimationAllTimer
        {
            get { return this.mouseAnimationAllTimer; }
            set
            {
                if (value < 0)
                    value = 0;
                if (this.mouseAnimationAllTimer == value)
                    return;

                this.mouseAnimationAllTimer = value;
            }
        }

        private int lRAnimationDistance = 0;
        /// <summary>
        /// 左右滑动动画距离
        /// </summary>
        [Description("左右滑动动画距离")]
        [Category("杂项")]
        [PropertyOrder(-188)]
        [DefaultValue(0)]
        public int LRAnimationDistance
        {
            get { return this.lRAnimationDistance; }
            set
            {
                if (this.lRAnimationDistance == value || value < 0)
                    return;

                this.lRAnimationDistance = value;
            }
        }

        private int height = 30;
        /// <summary>
        /// 高度
        /// </summary>
        [Description("高度")]
        [Category("杂项")]
        [PropertyOrder(-186)]
        [DefaultValue(30)]
        public int Height
        {
            get { return this.height; }
            set
            {
                if (this.height == value || value <= 0)
                    return;

                this.height = value;
                this.InitializeInvalidate();
            }
        }

        private TBMargin tBMargin = new TBMargin(0, 0);
        /// <summary>
        /// 上下外边距
        /// </summary>
        [Description("上下外边距")]
        [Category("杂项")]
        [PropertyOrder(-185)]
        [DefaultValue(typeof(TBMargin), "0,0")]
        public TBMargin TBMargin
        {
            get { return this.tBMargin; }
            set
            {
                if (value.Top < -1)
                    value.Top = -1;
                if (value.Bottom < -1)
                    value.Bottom = -1;
                if (this.tBMargin == value)
                    return;

                this.tBMargin = value;
                this.InitializeInvalidate();
            }
        }

        private LRMargin textLRMargin = new LRMargin(4, 4);
        /// <summary>
        /// 文本左右外边距
        /// </summary>
        [Description("文本左右外边距")]
        [Category("杂项")]
        [PropertyOrder(-184)]
        [DefaultValue(typeof(LRMargin), "4, 4")]
        public LRMargin TextLRMargin
        {
            get { return this.textLRMargin; }
            set
            {
                if (value.Left < 0)
                    value.Left = 0;
                if (value.Right < 0)
                    value.Right = 0;
                if (this.textLRMargin == value)
                    return;

                this.textLRMargin = value;
                this.Invalidate();
            }
        }

        private Color backNormalColor = Color.FromArgb(153, 204, 204);
        /// <summary>
        /// 背景颜色（正常）
        /// </summary>
        [Description(" 背景颜色（正常）")]
        [Category("杂项")]
        [PropertyOrder(-182)]
        [DefaultValue(typeof(Color), "153, 204, 204")]
        public Color BackNormalColor
        {
            get { return this.backNormalColor; }
            set
            {
                if (this.backNormalColor == value)
                    return;

                this.backNormalColor = value;
                this.Invalidate();
            }
        }

        private Color textNormalColor = Color.White;
        /// <summary>
        /// 文本颜色（正常）
        /// </summary>
        [Description(" 文本颜色（正常）")]
        [Category("杂项")]
        [PropertyOrder(-180)]
        [DefaultValue(typeof(Color), "White")]
        public Color TextNormalColor
        {
            get { return this.textNormalColor; }
            set
            {
                if (this.textNormalColor == value)
                    return;

                this.textNormalColor = value;
                this.Invalidate();
            }
        }

        private Color backEnterColor = Color.FromArgb(153, 204, 204);
        /// <summary>
        /// 背景颜色（鼠标进入）
        /// </summary>
        [Description(" 背景颜色（鼠标进入）")]
        [Category("杂项")]
        [PropertyOrder(-178)]
        [DefaultValue(typeof(Color), "153, 204, 204")]
        public Color BackEnterColor
        {
            get { return this.backEnterColor; }
            set
            {
                if (this.backEnterColor == value)
                    return;

                this.backEnterColor = value;
                this.Invalidate();
            }
        }

        private Color textEnterColor = Color.White;
        /// <summary>
        /// 文本颜色（鼠标进入）
        /// </summary>
        [Description(" 文本颜色（鼠标进入）")]
        [Category("杂项")]
        [PropertyOrder(-176)]
        [DefaultValue(typeof(Color), "White")]
        public Color TextEnterColor
        {
            get { return this.textEnterColor; }
            set
            {
                if (this.textEnterColor == value)
                    return;

                this.textEnterColor = value;
                this.Invalidate();
            }
        }

        private Color splitterLineColor = Color.Empty;
        /// <summary>
        /// 分割线颜色
        /// </summary>
        [Description(" 分割线颜色")]
        [Category("杂项")]
        [PropertyOrder(-170)]
        [DefaultValue(typeof(Color), "")]
        [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
        public Color SplitterLineColor
        {
            get { return this.splitterLineColor; }
            set
            {
                if (this.splitterLineColor == value)
                    return;

                this.splitterLineColor = value;
                this.Invalidate();
            }
        }

        private bool imageVisible = false;
        /// <summary>
        /// 是否显示图片
        /// </summary>
        [Description("是否显示图片")]
        [Category("杂项")]
        [PropertyOrder(-160)]
        [DefaultValue(false)]
        public bool ImageVisible
        {
            get { return this.imageVisible; }
            set
            {
                if (this.imageVisible == value)
                    return;

                this.imageVisible = value;
                this.Invalidate();
            }
        }

        private LRMargin imageLRMargin = new LRMargin(4, 14);
        /// <summary>
        /// 图片左右外边距
        /// </summary>
        [Description("图片左右外边距")]
        [Category("杂项")]
        [PropertyOrder(-158)]
        [DefaultValue(typeof(LRMargin), "4, 14")]
        public LRMargin ImageLRMargin
        {
            get { return this.imageLRMargin; }
            set
            {
                if (value.Left < 0)
                    value.Left = 0;
                if (value.Right < 0)
                    value.Right = 0;
                if (this.imageLRMargin == value)
                    return;

                this.imageLRMargin = value;
                this.Invalidate();
            }
        }

        private Size imageSize = new Size(14, 14);
        /// <summary>
        /// 图片Size
        /// </summary>
        [Description("图片Size")]
        [Category("杂项")]
        [PropertyOrder(-156)]
        [DefaultValue(typeof(Size), "14,14")]
        public Size ImageSize
        {
            get { return this.imageSize; }
            set
            {
                if (this.imageSize == value || value.Width <= 0 || value.Height < 0)
                    return;

                this.imageSize = value;
                this.Invalidate();
            }
        }

        private Image image = null;
        /// <summary>
        /// 图片(通用)
        /// </summary>
        [Description("图片(通用)")]
        [Category("杂项")]
        [PropertyOrder(-154)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.Repaint)]
        public Image Image
        {
            get { return this.image; }
            set
            {
                if (this.image == value)
                    return;

                this.image = value;
                this.Invalidate();
            }
        }

        #endregion

        #region 字段

        private SingleAccordion owner = null;

        #endregion

        public SingleAccordionLabelNodeStyle(SingleAccordion owner)
        {
            this.owner = owner;
        }

        #region 私有方法

        /// <summary>
        /// 刷新控件
        /// </summary>
        private void Invalidate()
        {
            if (this.owner != null)
            {
                this.owner.Invalidate();
            }
        }

        /// <summary>
        /// 重新计算控件并刷新控件
        /// </summary>
        private void InitializeInvalidate()
        {
            if (this.owner != null)
            {
                this.owner.UpdateRealityRectangle();
                this.owner.UpdateAllNodeRectangle();
                this.owner.UpdateScrollRectangle();
                this.owner.Invalidate();
            }
        }

        #endregion
    }

}
